﻿using Asion.Dapper.SqlBuilder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Asion.Dapper
{
    public interface IOrderBy : ICondition
    {

    }


    public class OrderBy : BaseCondition, IOrderBy, IGetSql
    {
        private const string asc = "asc";

        private const string desc = "desc";


        private string condition;

        private OrderByConditionType type;


        /// <summary>
        /// single order default asc
        /// </summary>
        /// <param name="field"></param>
        /// <param name="type"></param>
        public OrderBy(string field)
        {
            condition = field;
            this.type = OrderByConditionType.Asc;
        }


        /// <summary>
        /// single order
        /// </summary>
        /// <param name="field"></param>
        /// <param name="type"></param>
        public OrderBy(string field, OrderByConditionType type)
        {
            condition = field;
            this.type = type;
        }

        /// <summary>
        /// mult order 
        /// <para>string[]{"id","name"}  = id,name</para>
        /// </summary>
        /// <param name="fields"></param>
        /// <param name="type"></param>
        public OrderBy(string[] fields, OrderByConditionType type)
        {
            condition = string.Join(",", fields);
            this.type = type;
        }

        public override string BuildSql()
        {
            return $" order by {this.condition} " + type.ToString().ToLower();
        }



    }



    public class OrderByConditonFactory
    {
        public OrderByConditonFactory(IOrderBy condtion)
        {
            where = condtion;

        }

        private IOrderBy where;



        public string GetSql()
        {

            if (where is OrderBy)
            {
                var condtion = where as OrderBy;

                var result = condtion.GetSql();

                return result;
            }
            throw new NotImplementedException("where condition");
        }
    }



}
